package com.jyb.qiyefuwu.view.adpater;

import android.content.Context;
import android.text.TextUtils;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.bumptech.glide.request.RequestOptions;
import com.jyb.qiyefuwu.BR;
import com.jyb.qiyefuwu.R;
import com.jyb.qiyefuwu.databinding.FwItemIntellpropnBinding;
import com.jyb.qiyefuwu.entity.IntellDataListItem;
import com.swgk.core.recyclerview.adapter.BaseRecycleAdapter;
import com.swgk.core.recyclerview.adapter.ItemViewHolder;

import java.util.ArrayList;

public class Fw_IntellpropAdapter extends BaseRecycleAdapter<IntellDataListItem> {
    int position;
    public Fw_IntellpropAdapter(Context context, int position) {
        super(context,R.layout.fw_item_intellpropn, new ArrayList<>());
        this.position = position;
    }

    @Override
    public void convert(ItemViewHolder holder, IntellDataListItem o) {
        if(holder.getmBinding() instanceof FwItemIntellpropnBinding){

            holder.setBinding(BR.viewdata,o);
            if(!TextUtils.isEmpty(o.getPublishType())) {
                switch (o.getPublishType()) {
                    case "1":
                        ((FwItemIntellpropnBinding) holder.getmBinding()).tvUserTag.setText("企业");
                        ((FwItemIntellpropnBinding) holder.getmBinding()).tvUserTag.setBackgroundResource(R.drawable.shape_radius_1_solid_bule);
                        break;
                    case "2":
                        ((FwItemIntellpropnBinding) holder.getmBinding()).tvUserTag.setText("团队");
                        ((FwItemIntellpropnBinding) holder.getmBinding()).tvUserTag.setBackgroundResource(R.drawable.shape_tage_back_orgre);
                        break;
                    case "0":
                        ((FwItemIntellpropnBinding) holder.getmBinding()).tvUserTag.setText("个人");
                        ((FwItemIntellpropnBinding) holder.getmBinding()).tvUserTag.setBackgroundResource(R.drawable.shape_radius_1_solid_bule);
                        break;

                }
            }

            ((FwItemIntellpropnBinding) holder.getmBinding()).imageFollow.setOnClickListener(view -> {
                if(onItemClick!=null){
                    onItemClick.onItemClick(o,-1);
                }
            });

            switch (position){
                case 0:
                    if(!TextUtils.isEmpty(o.getImg())){
                        Glide.with(context).load(o.getImg()).apply(RequestOptions.bitmapTransform(new RoundedCorners(2))).into(((FwItemIntellpropnBinding) holder.getmBinding()).imageView);
                    }
                    break;
                case 1:
                    if (o.getImg() != null && !o.getImg().equals("")) {
                        Glide.with(context).load(o.getImg()).apply(RequestOptions.bitmapTransform(new RoundedCorners(2))).into(((FwItemIntellpropnBinding) holder.getmBinding()).imageView);
                    } else {
//            roundImageView.setImageResource(R.mipmap.morentu_change);
                        switch (o.getCategoryName()){
                            case "发明专利":
                                Glide.with(context).load(R.mipmap.fw_famingzhuanli_for_patent_publish).into(((FwItemIntellpropnBinding) holder.getmBinding()).imageView);
                                break;
                            case "实用新型":
                                Glide.with(context).load(R.mipmap.fw_shiyongxinxing_patent_publish).into(((FwItemIntellpropnBinding) holder.getmBinding()).imageView);
                                break;
                            case "外观设计":
                                Glide.with(context).load(R.mipmap.fw_waiguansheji_patent_publish).into(((FwItemIntellpropnBinding) holder.getmBinding()).imageView);
                                break;
                        }
                    }
                    break;
                case 2:
                    if (o.getImg() != null && !o.getImg().equals("")) {
                        Glide.with(context).load(o.getImg()).apply(RequestOptions.bitmapTransform(new RoundedCorners(2))).into(((FwItemIntellpropnBinding) holder.getmBinding()).imageView);
                    } else {
                        ((FwItemIntellpropnBinding) holder.getmBinding()).imageView.setImageResource(R.mipmap.morentu_change);
                    }

                    break;
            }
        }
    }
}
